﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Dynamic;
using Newtonsoft.Json;
using System.Net.Http;

namespace WebAuthTest.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Name()
        {
            dynamic obj = new ExpandoObject();
            obj.Name = "Liao";

            return Jsonp(obj);
        }

        private ActionResult Jsonp(object data)
        {
            var callback = Request["callback"];
            var result = JsonConvert.SerializeObject(data);

            return string.IsNullOrWhiteSpace(callback) ?
                Content(result)as ActionResult :
                JavaScript(string.Format("{0}({1})", callback, result)) as ActionResult;
        }


        public ActionResult Proxy()
        {
            HttpClient httpClient = new HttpClient();
            return null;
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}